package com.yanqu.road.server.cmd.activity.unionchest;

import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.UnionChestProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.*;

@Cmd(code = CrossProtocol.C3_UNIONCHEST_BOX_SYNC, desc = "宝箱数据同步给商会成员")
public class Cross3UnionChestBoxSyncCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        UnionChestProto.CrossUnionChestBoxSyncMsg reqMsg = UnionChestProto.CrossUnionChestBoxSyncMsg.parseFrom(packet.getBytes());
        Map<Long, CrossUnionMember> unionMemberMap = CrossUnionMgr.getUnionMemberMap(reqMsg.getUnionId());
        for (CrossUnionMember member : unionMemberMap.values()) {
            if (member.getUserId() == packet.getPlayerId()) {
                continue;
            }
            MessageHelper.sendPacket(member.getServerId(), member.getUserId(),
                    YanQuMessageUtils.buildMessage(ClientProtocol.U_UNIONCHEST_BOX_SYNC, reqMsg.getSyncMsg().toBuilder()));
        }
    }

    @Override
    public void sendData() {

    }
}
